home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / rwvector.lha / RWVector2.1 / src / xblock.cc < prev    next >
C/C++ Source or Header  |  1989-08-18  |  2KB  |  100 lines

  1. /*
  2.  *    Definitions for <T>Block
  3.  *
  4.  *    Copyright (C) 1988, 1989.
  5.  *
  6.  *    Dr. Thomas Keffer
  7.  *    Rogue Wave Associates
  8.  *    P.O. Box 85341
  9.  *    Seattle WA 98145-1341
  10.  *
  11.  *    Permission to use, copy, modify, and distribute this
  12.  *    software and its documentation for any purpose and
  13.  *    without fee is hereby granted, provided that the
  14.  *    above copyright notice appear in all copies and that
  15.  *    both that copyright notice and this permission notice
  16.  *    appear in supporting documentation.
  17.  *    
  18.  *    This software is provided "as is" without any
  19.  *    expressed or implied warranty.
  20.  *
  21.  *
  22.  *    @(#)xblock.cc    2.1    8/18/89
  23.  */
  24.  
  25.  
  26. #define NO_VECTOR_MATHFUN
  27. #include "rw/<T>Vec.h"
  28.  
  29. <T>Block::<T>Block(unsigned n)
  30. {
  31.  
  32. #ifdef DEBUG
  33.   if(this){
  34.     RWnote("<T>Block::<T>Block()", "Not on free store.");
  35.     RWerror(FATAL);
  36.   }
  37. #endif
  38. #ifdef __ATT__
  39.   // cfront can't handle zero lengthed arrays
  40.   int nxtra = (n<=1 ? 0 : n-1);
  41. #else
  42. #define nxtra n-1
  43. #endif  
  44.   this = (<T>Block *)new char[sizeof(<T>Block) + sizeof(<T>)*(nxtra)];
  45.   npts = n;
  46.   refs = 1;
  47. }
  48.  
  49. <T>Block::<T>Block(unsigned n, <T> val)
  50. {
  51.  
  52. #ifdef DEBUG
  53.   if(this){
  54.     RWnote("<T>Block", "Not on free store.");
  55.     RWerror(FATAL);
  56.   }
  57. #endif
  58. #ifdef __ATT__
  59.   int nxtra = (n<=1 ? 0 : n-1);
  60. #else
  61. #define nxtra n-1
  62. #endif  
  63.   this = (<T>Block *)new char[sizeof(<T>Block) + sizeof(<T>)*(nxtra)];
  64.   refs = 1;
  65.   register int i = npts = n;
  66.   register <T>* dp = data();
  67.   register <T> value = val;
  68.   while(i--) *dp++ = value;
  69. }
  70.  
  71. <T>Block::<T>Block(unsigned n, <T> val, <T> by)
  72. {
  73.  
  74. #ifdef DEBUG
  75.   if(this){
  76.     RWnote("<T>Block", "Not on free store.");
  77.     RWerror(FATAL);
  78.   }
  79. #endif
  80. #ifdef __ATT__
  81.   int nxtra = (n<=1 ? 0 : n-1);
  82. #else
  83. #define nxtra n-1
  84. #endif  
  85.   this = (<T>Block *)new char[sizeof(<T>Block) + sizeof(<T>)*(nxtra)];
  86.   refs = 1;
  87.   register int i = npts = n;
  88.   register <T>* dp = data();
  89.   register <T> value = val;
  90.   register <T> byvalue = by;
  91.   while(i--) {*dp++ = value; value += byvalue;}
  92. }
  93.  
  94. <T>Block::~<T>Block()
  95. {
  96.   if(--refs) this = 0;
  97. }
  98.  
  99.         
  100.